package com.nixsolutions.service;

import com.nixsolutions.bean.User;
import com.nixsolutions.dao.UserDao;
import java.util.List;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author yakimovich
 */
public class UserServiceImpl implements UserService {

    private static org.apache.commons.logging.Log logger = LogFactory.getLog(UserServiceImpl.class);
    
    @Qualifier("userDao")
    @Autowired
    private UserDao userDao;

    public UserServiceImpl() {
    }

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    @Transactional
    public void create(User user) {

        try {
            userDao.create(user);
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }

    @Override
    @Transactional
    public void update(User user) {

        try {
            userDao.update(user);
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }

    @Override
    @Transactional
    public void remove(User user) {

        try {
            userDao.remove(user);
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }

    @Override
    @Transactional
    public List<User> findAll() {

        try {
            return userDao.findAll();
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }

    @Override
    @Transactional
    public User findByLogin(String userLogin) {
        try {
            return userDao.findByLogin(userLogin);
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }

    @Override
    @Transactional
    public User findByEmail(String email) {
        try {
            return userDao.findByEmail(email);
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }
}
